package com.fr.base.core;

import com.fr.base.xml.BaseXMLUtils;
import java.awt.Image;
import java.lang.reflect.Array;
import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class ComparatorUtils
{
  private static final double NUMBER_FOR_PRECISE_COMPARE = 1.E-009D;

  public static int compare(Object paramObject1, Object paramObject2)
  {
    if ((paramObject1 == null) || (paramObject2 == null))
      return ((paramObject1 == null) ? -1 : ((paramObject1 == null) && (paramObject2 == null)) ? 0 : 1);
    if ((paramObject1 instanceof Date) || (paramObject2 instanceof Date))
    {
      Date localDate1 = DateUtils.object2Date(paramObject1, true);
      Date localDate2 = DateUtils.object2Date(paramObject2, true);
      long l1 = (localDate1 == null) ? 0L : localDate1.getTime();
      long l2 = (localDate2 == null) ? 0L : localDate2.getTime();
      return ((l1 > l2) ? 1 : (l1 == l2) ? 0 : -1);
    }
    if ((paramObject1 instanceof Number) && (!(paramObject2 instanceof Number)))
      try
      {
        paramObject2 = Double.valueOf(paramObject2.toString());
      }
      catch (Throwable localThrowable1)
      {
      }
    if ((paramObject2 instanceof Number) && (!(paramObject1 instanceof Number)))
      try
      {
        paramObject1 = Double.valueOf(paramObject1.toString());
      }
      catch (Throwable localThrowable2)
      {
      }
    if ((paramObject1 instanceof Number) && (paramObject2 instanceof Number))
      return compare(((Number)paramObject1).doubleValue(), ((Number)paramObject2).doubleValue());
    return paramObject1.toString().toLowerCase().compareTo(paramObject2.toString().toLowerCase());
  }

  public static int compare(double paramDouble1, double paramDouble2)
  {
    double d = paramDouble1 - paramDouble2;
    return ((d > 0.0D) ? 1 : (java.lang.Math.abs(d) < 1.E-009D) ? 0 : -1);
  }

  public static int compare(Comparator paramComparator, Object paramObject1, Object paramObject2)
  {
    if ((paramComparator instanceof Collator) && (paramObject1 != null) && (paramObject2 != null))
      return paramComparator.compare(paramObject1.toString().toLowerCase(), paramObject2.toString().toLowerCase());
    return compare(paramObject1, paramObject2);
  }

  public static boolean equals(Object paramObject1, Object paramObject2)
  {
    int i;
    if (paramObject1 == paramObject2)
      return true;
    if ((paramObject1 == null) || (paramObject2 == null))
      return ((paramObject1 == null) && (paramObject2 == null));
    if ((paramObject1 instanceof Date) || (paramObject2 instanceof Date))
      return (compare(paramObject1, paramObject2) == 0);
    try
    {
      if ((paramObject1 instanceof Number) && (!(paramObject2 instanceof Number)))
        paramObject2 = Double.valueOf(paramObject2.toString());
      if ((paramObject2 instanceof Number) && (!(paramObject1 instanceof Number)))
        paramObject1 = Double.valueOf(paramObject1.toString());
    }
    catch (NumberFormatException localNumberFormatException)
    {
      return false;
    }
    if ((paramObject1 instanceof Number) && (paramObject2 instanceof Number))
      return (compare(paramObject1, paramObject2) == 0);
    if ((paramObject1.getClass().isArray()) && (paramObject2.getClass().isArray()))
    {
      i = Array.getLength(paramObject1);
      int j = Array.getLength(paramObject2);
      if (i != j)
        return false;
      for (int k = 0; k < i; ++k)
        if (!(equals(Array.get(paramObject1, k), Array.get(paramObject2, k))))
          return false;
      return true;
    }
    if ((paramObject1 instanceof List) && (paramObject2 instanceof List))
    {
      if (((List)paramObject1).size() != ((List)paramObject2).size())
        return false;
      for (i = 0; i < ((List)paramObject1).size(); ++i)
        if (!(equals(((List)paramObject1).get(i), ((List)paramObject2).get(i))))
          return false;
      return true;
    }
    return paramObject1.equals(paramObject2);
  }

  public static boolean equals_exactly(Object paramObject1, Object paramObject2)
  {
    if ((paramObject1 == null) || (paramObject2 == null))
      return ((paramObject1 == null) && (paramObject2 == null));
    if ((paramObject1 instanceof Date) && (paramObject2 instanceof Date))
      return (((Date)paramObject1).getTime() == ((Date)paramObject2).getTime());
    if ((paramObject1 instanceof Number) && (paramObject2 instanceof Number))
      return (((Number)paramObject1).doubleValue() == ((Number)paramObject2).doubleValue());
    return paramObject1.equals(paramObject2);
  }

  public static boolean imageEquals(Image paramImage1, Image paramImage2)
  {
    if ((paramImage1 == null) || (paramImage2 == null))
      return ((paramImage1 == null) && (paramImage2 == null));
    byte[] arrayOfByte1 = BaseXMLUtils.encodeImage(paramImage1);
    byte[] arrayOfByte2 = BaseXMLUtils.encodeImage(paramImage2);
    if (arrayOfByte1.length != arrayOfByte2.length)
      return false;
    for (int i = 0; i < arrayOfByte1.length; ++i)
      if (arrayOfByte1[i] != arrayOfByte2[i])
        return false;
    return true;
  }

  public static boolean tableDataColumnNameEquals(String paramString1, String paramString2)
  {
    if ((paramString1 == null) || (paramString2 == null))
      return ((paramString1 == null) && (paramString2 == null));
    return paramString1.toLowerCase().equals(paramString2.toLowerCase());
  }

  public static boolean equals(Iterator paramIterator1, Iterator paramIterator2)
  {
    if (paramIterator1 == null)
      paramIterator1 = Collections.EMPTY_LIST.iterator();
    if (paramIterator2 == null)
      paramIterator2 = Collections.EMPTY_LIST.iterator();
    boolean bool1 = paramIterator1.hasNext();
    for (boolean bool2 = paramIterator2.hasNext(); (bool1) && (bool2); bool2 = paramIterator2.hasNext())
    {
      if (!(equals(paramIterator1.next(), paramIterator2.next())))
        return false;
      bool1 = paramIterator1.hasNext();
    }
    return (bool1 == bool2);
  }
}